module(..., package.seeall)

-- The DEBUG Level designates fine-grained instring.formational events that are most
-- useful to debug an application
DEBUG = "DEBUG"

-- The INFO level designates instring.formational messages that highlight the
-- progress of the application at coarse-grained level
INFO = "INFO"

-- The WARN level designates potentially harmful situations
WARN = "WARN"

-- The ERROR level designates error events that might still allow the
-- application to continue running
ERROR = "ERROR"

-- The FATAL level designates very severe error events that will presumably
-- lead the application to abort
FATAL = "FATAL"

local LEVEL = {
	[DEBUG] = 1,
	[INFO]  = 2,
	[WARN]  = 3,
	[ERROR] = 4,
	[FATAL] = 5,
}

local function _log_enable(log,lvl)
	return LEVEL[log.level]<=(LEVEL[lvl] or 0)
end

function make_logger(module_name, params, level)
	if module_name then
		require("logging."..module_name)
		local logger, err = logging[module_name](unpack(params))
		assert(logger, "Could not initialize logger: "..(err or ""))
		if level then 
			logger:setLevel(logging[level])
			logger.chkLevel=_log_enable
		end
		return logger
	else
		return {
			debug = function(...) end, -- do nothing
			info  = function(...) end,
			error = function(...) end,
			fatal = function(...) end,
			warn  = function(...) end,
			chkLevel=_log_enable,
		}
	end
end

require "logging"

defaultlog = make_logger('console',{},GLOGLVL or 'DEBUG')

